package com.smart_campus.teg.controller;

import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.common.ResultObj;
import com.smart_campus.teg.service.TegClassService;
import com.smart_campus.teg.vo.ClassVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("class")
public class ClassController {
    @Autowired
    private TegClassService tegClassService;


    /**
     * 查询所有
     * @param vo
     * @return
     */
@RequestMapping("zzzz")
    public DataGridView zzzz(ClassVo vo){
    return  tegClassService.selClass(vo);
}

    /**
     * 添加班级
     * @param
     * @return ResultObj
     */
    @RequestMapping("classAdd")
    public ResultObj MajorAdd(ClassVo classVo){

        try {
            tegClassService.insert(classVo);
            return ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.ADD_ERROR;
        }
    }

    /**
     * 删除班级方法
     * @param id
     * @return ResultObj
     */
    @RequestMapping("classdelete")
    public ResultObj classdelete(Integer id){
        try {
            tegClassService.deleteByPrimaryKey(id);
            return ResultObj.Class_DELETE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.Class_DELETE_NO;
        }
    }


    @RequestMapping("classdeleteBatch")
    public ResultObj classdeleteBatch(Integer[] ids){
        try {
            for (Integer id : ids) {
                tegClassService.deleteByPrimaryKey(id);
            }

            return ResultObj.Class_DELETE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.Class_DELETE_NO;
        }
    }

    /**
     * 修改班级方法
     * @param
     * @return ResultObj
     */
    @RequestMapping("ClassUpdate")
    public ResultObj ClassUpdate(ClassVo classVo){
        try {
            tegClassService.updateByPrimaryKeySelective(classVo);
            return ResultObj.Class_UPDATE_YES;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.Class_UPDATE_NO;
        }
    }


    /**
     * 查询班级name
     * @param
     * @return ResultObj
     */
    @RequestMapping("selclassname")
    public DataGridView selclassname(ClassVo classVo){
        return  tegClassService.selClassname();
    }

}
